package com.proton.carepatchtemp.database.daomanager;

import com.proton.carepatchtemp.database.gen.ProfileDao;
import com.proton.carepatchtemp.database.table.Profile;

import java.util.List;

/**
 * Created by MoonlightSW on 2017/2/21.
 */

public class ProfileManager {
    private ProfileDao mProfileDao;

    public ProfileManager() {
        mProfileDao = GreenDaoManager.get().getmDaoSession().getProfileDao();
    }

    public static void deleteProfile(Long id) {
        getProfileDao().deleteByKey(id);
    }

    public static Profile getProfile(Long id) {
        return getProfileDao().load(id);
    }

    public static List<Profile> getAll() {
        return getProfileDao().loadAll();
    }

    public static void insertOrReplace(Profile profile) {
        getProfileDao().insertOrReplace(profile);
    }

    public static void update(Profile profile) {
        //update之后要清除缓存，否则获取的数据异常
        getProfileDao().update(profile);
        GreenDaoManager.get().getmDaoSession().clear();
    }

    public static void insertOrReplaceInTx(List<Profile> profiles) {
        getProfileDao().insertOrReplaceInTx(profiles);
    }

    private static ProfileDao getProfileDao() {
        return GreenDaoManager.get().getmDaoSession().getProfileDao();
    }
}
